﻿using System;
using System.Collections.Generic;
using QFramework;
using UnityEngine;

namespace ProjectIndieFarm
{
    public class SwapItemCommand : AbstractCommand
    {
        private int slotIndexA = 0;
        private int slotIndexB = 0;

        public SwapItemCommand(int indexA, int indexB)
        {
            slotIndexA = indexA;
            slotIndexB = indexB;
        }

        protected override void OnExecute()
        {
            var toolbarSystem = this.GetSystem<IToolbarSystem>();
            var slotA = toolbarSystem.Slots[slotIndexA];
            var slotB = toolbarSystem.Slots[slotIndexB];

            var itemID = slotA.ItemID.Value;
            var count = slotA.Count.Value;
            slotA.ItemID.Value = slotB.ItemID.Value;
            slotA.Count.Value = slotB.Count.Value;
            slotB.ItemID.Value = itemID;
            slotB.Count.Value = count;
        }
    }
}
